#include "SceneModel/BaseModel/Plane.h"

namespace GCRE {
	namespace SceneModel {
		
		using namespace BasicType;

		Plane::Plane( const Plane& plane )
		{
			m_Normal = plane.m_Normal;
			m_Distance = plane.m_Distance;
		}

		Plane::Plane( const BasicType::SFVec3f& n, BasicType::SFFloat d ) : 
		m_Normal( n ), m_Distance( d )
		{

		}

		Plane::Plane( BasicType::SFFloat a, BasicType::SFFloat b, BasicType::SFFloat c, BasicType::SFFloat d ) : 
		m_Normal( a, b, c ), m_Distance( d )
		{

		}

		Plane::Plane( const BasicType::SFVec3f& n, const BasicType::SFVec3f& p ) : 
		m_Normal( n )
		{
			m_Distance = -static_cast<SFFloat>( m_Normal * p );
		}

		Plane::Plane( const BasicType::SFVec3f& A, const BasicType::SFVec3f& B, const BasicType::SFVec3f& C )
		{
			SFVec3f AB = B - A;
			SFVec3f AC = C - A;
			m_Normal = AB.Cross( AC );
			m_Distance = -static_cast<SFFloat>( m_Normal * A );
		}

		Plane::Plane() : 
		m_Normal( 0.0F, 1.0F, 0.0F), m_Distance( 0.0F )
		{

		}

		Plane& Plane::operator=( const Plane& plane )
		{
			m_Normal = plane.m_Normal;
			m_Distance = plane.m_Distance;
			return *this;
		}

		void Plane::Set( BasicType::SFFloat a, BasicType::SFFloat b, BasicType::SFFloat c, BasicType::SFFloat d )
		{
			m_Normal.Set( a, b, c );
			m_Distance = d;
		}
	}
}